// import * as THREE from "three"
let THREE=require('three');

class SkyBoxMgr {

  static getInstance() {
    if (!SkyBoxMgr.instance) {
      SkyBoxMgr.instance = new SkyBoxMgr();
    }
    return SkyBoxMgr.instance;
  }

  constructor() {

  }


  onProgressSkyBox = function (xhr) {
    console.log('加载天空盒完成百分比' + (xhr.loaded / xhr.total * 100) + '%');
  }

  //旧版本创建天空盒skyBox
  createSkyBox(skyBoxUrl) {
    //"http://iddd.oss-cn-shanghai.aliyuncs.com/sheji/public/model/iddd/skyboxs/sky5/"
    // let r = "http://192.168.1.188:10077/skyboxs/sky5/";
    let r = skyBoxUrl;
    let urls = [r + "Right.png", r + "Left.png",
      r + "Up.png", r + "Down.png",
      r + "Back.png", r + "Front.png"];
    let CubeTextureLoader = new THREE.CubeTextureLoader();
    let textureCube = CubeTextureLoader.load(urls, this.onProgressSkyBox);
    textureCube.format = THREE.RGBFormat;
    textureCube.mapping = THREE.CubeReflectionMapping;
    textureCube.encoding = THREE.sRGBEncoding;
    return textureCube;
  }


  //新版本创建天空盒返回promise对象
  createSkyBoxAsync(skyBoxUrl) {
    let r = skyBoxUrl;
    let urls = [r + "Right.png", r + "Left.png",
      r + "Up.png", r + "Down.png",
      r + "Back.png", r + "Front.png"];
    let CubeTextureLoader = new THREE.CubeTextureLoader();
    return CubeTextureLoader.loadAsync(urls, this.onProgressSkyBox)
  }

}

export default SkyBoxMgr;
